-- 此项目仅供呼吸测试
local info = {
    {"3组投石机所需材料【打蜂后】", 
    [[
        6木板 6电子元件
        54树枝 270石头 63草 21蜘蛛丝
    ]]},
    -- {字符串1, 字符串2}

    {"奶奶岛修建材料",[[
        1、10切割机碎片 10木板 1萤火虫
        2、10大理石 5石砖 3荧光果
        3、5月岩 5绳子 5牛毛地皮
    ]]}
}

function GLOBAL.showme(i)
    print("***************************")
    if info[i] and info[i][1] and info[i][2] then
        print("##", info[i][1], "##\n")
        print(info[i][2])
    else
        print("目录:")
        for k,v in pairs(info)do
            if v and type(v[1]) == "string" then
                print(k.."、"..v[1])
            end
        end
    end
end

function GLOBAL.showfunc()
    print("nearEnt(name)")
    print("nearSlot(id)")
    print("nearFX(fx_name)")
    print("printDist(a_ent, b_ent)")
    print("nearEnts(range, allowTags, banTags)")
    print("getTags(ent)")
    print("compTags(tags1, tags2)")
    print("getItems(prefab, tags)")
    print("getItem(prefab, tag)")
    print("getSlot(slot)")
end

GLOBAL.nearEnt = PlayerFindEnt
GLOBAL.nearEnts = PlayerFindEnts
function GLOBAL.nearFX(name)
    return PlayerFindEnt(name, nil, nil, {})
end

function GLOBAL.nearSlot(loc)
    return GLOBAL.ThePlayer.replica.inventory:GetItemInSlot(loc)
end

function GLOBAL.printDist(ent1, ent2)
    if ent1 and ent1:IsValid() and ent2 and ent2:IsValid() then
        print(math.sqrt(ent1:GetPosition():DistSq(ent2:GetPosition())))
    end
end

function GLOBAL.getTags(ent)
    local tags_string = ent:GetDebugString():match("Tags:(.-)\n")
    return tags_string and tags_string:split(" ") or {}
end

function GLOBAL.compTags(tags1, tags2)
    local dif1 = {}
    local dif2 = {}
    for _,tag in pairs(tags1)do
        if not table.contains(tags2, tag) then
            table.insert(dif1, #dif1+1, tag)
        end
    end
    print("在 TAG1 而不在 TAG2 中:")
    print(unpack(dif1))
    for _,tag in pairs(tags2)do
        if not table.contains(tags1, tag) then
            table.insert(dif2, #dif2+1, tag)
        end
    end
    print("在 TAG2 而不在 TAG1 中:")
    print(unpack(dif2))
end

function GLOBAL.getItems(...)
    return GetItemsFromAll(...)
end

function GLOBAL.getItem(...)
    return GetItemFromAll(...)
end

function GLOBAL.getSlot(...)
    return GetEquippedItemFrom(...)
end

AddPrefabPostInit("world", function(world)
    world:ListenForEvent("playeractivated", function(world, player)
        print("*******************************")
        print("玩家进入")
        print(player and player.name)
        print("*******************************")
    end)
end)


-- if  GetModConfigData("sw_eyeofterror") and GetModConfigData("sw_author") then
--     local id = 0
--     local oldSendRPCToServer = GLOBAL.SendRPCToServer
--     function GLOBAL.SendRPCToServer(rpc, actcode, sth, ...)
--         local rpc_init, act_init
--         id = id + 1
--         for k,v in pairs(GLOBAL.RPC)do
--             if rpc == v then
--                 rpc_init = k
--             end
--         end
--         if not rpc_init then rpc_init = rpc end
--         for k,v in pairs(GLOBAL.ACTIONS)do
--             if v.code == actcode then
--                 act_init = k
--             end
--         end
--         if not act_init then act_init = actcode end
--         print("ID:", id, rpc_init, act_init, "sth:",sth, "其他参数：", ...)
--         oldSendRPCToServer(rpc, actcode, sth, ...)
--     end
-- end